<template>
  <!-- 佣金业绩 -->
  <div class="app-container">
    <!-- 查询模块 -->
    <div class="formDiv">
      <el-form ref="form" :inline="true" :model="form" label-width="180px">
        <el-row>
          <el-col :span="8">
            <el-form-item label="订单编号">
              <el-input v-model="form.order_sn" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="客户姓名/手机号">
              <el-input v-model="form.username" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="机构名称">
              <el-select v-model="form.hospital_id" placeholder="请选择" clearable filterable>
                <el-option
                  v-for="item in Mechanisms"
                  :key="item.value"
                  :label="item.hospital_name"
                  :value="item.id"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="地区">
              <el-select v-model="form.province_id" placeholder="请选择" clearable filterable>
                <el-option
                  v-for="item in options"
                  :key="item.value"
                  :label="item.name"
                  :value="item.id"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>

          <!-- <el-col :span="8">
            <el-form-item label="级别">
              <el-select v-model="form.order_status" placeholder="请选择" clearable>
                <el-option
                  v-for="(item,index) in statusType"
                  :key="index"
                  :label="item.name"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
          </el-col>-->
          <el-col :span="8">
            <el-form-item label="板块">
              <el-select v-model="form.module_id" placeholder="请选择" clearable>
                <el-option
                  v-for="(item,index) in statusType"
                  :key="index"
                  :label="item.name"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="城市合伙人姓名/手机号">
              <el-input v-model="form.partner_name" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="发起人/联合发起人(姓名/手机号)">
              <el-input v-model="form.partner_pid" clearable />
            </el-form-item>
          </el-col>
          <!-- <el-col :span="8">
            <el-form-item label="发起人姓名/手机号">
              <el-input v-model="form.partner_pid" clearable />
            </el-form-item>
          </el-col> -->
          <el-col :span="8">
            <el-form-item label="核销日期" width="236">
              <el-date-picker
                v-model="use_time"
                value-format="yyyy-MM-dd HH:mm:ss"
                type="daterange"
                range-separator="-"
                start-placeholder="开始时间"
                end-placeholder="结束时间"
                :default-time="['00:00:00', '23:59:59']"
              />
            </el-form-item>
          </el-col>
          <el-col :span="6" :offset="18">
            <el-form-item>
              <el-button type="primary" @click="handleSearch">查询</el-button>
              <!-- <el-button type="primary" @click="handleExport">导出</el-button> -->
              <!-- <Exprotcomponent :params="form" url="admin/order/card_ticket_export" type="php"></Exprotcomponent> -->
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <!-- 主页列表 -->
    <div class="listDiv" v-loading="tableLoading">
      <el-table ref="tableData" :data="tableData" style="width: 100%" height="500px">
        <!--   -->
        <el-table-column
          fixed
          type="index"
          label="编号"
          width="50"
          align="center"
          :index="table_index"
        />
        <el-table-column label="订单编号" prop="order_id" align="center"></el-table-column>
        <el-table-column label="客户信息" prop align="center" width="120px">
          <template slot-scope="scope">
            <span>{{scope.row.user_name}}</span>
            <span>{{scope.row.phone}}</span>
          </template>
        </el-table-column>
        <el-table-column label="项目名称" prop="project_name" align="center" width="120px"></el-table-column>
        <el-table-column label="支付金额" prop="pay_amount" align="center" width="120px"></el-table-column>
        <el-table-column label="机构名称" prop="hospital.hospital_name" align="center" width="120px" />
        <el-table-column
          label="地区"
          prop="hospital.hospital_province.name"
          align="center"
          width="120px"
        />
        <!-- 板块 默认为2 2华悦口腔（口腔） 3华视优选（眼科） 4美分享PLUS'（医美） -->
        <el-table-column label="板块" prop="app_type" align="center" width="120px">
          <template slot-scope="scope">
            <span v-if="scope.row.app_type==2">华悦口腔（口腔）</span>
            <span v-if="scope.row.app_type==3">华视优选（眼科）</span>
            <span v-if="scope.row.app_type==4">美分享PLUS（医美）</span>
          </template>
        </el-table-column>
        <el-table-column label="城市合伙人信息" prop align="center" width="120px">
          <template
            slot-scope="scope"
            v-if="scope.row.partner_identity&&scope.row.partner_identity.get_pid&&scope.row.partner_identity.get_pid.level_id==3"
          >
            <span>{{scope.row.partner_identity.get_pid.realname}}</span>
            <span>{{scope.row.partner_identity.get_pid.phone}}</span>
          </template>
        </el-table-column>
        <el-table-column label="发起人信息" prop align="center" width="120px">
          <template
            slot-scope="scope"
            v-if="scope.row.partner_identity&&scope.row.partner_identity.get_pid&&scope.row.partner_identity.get_pid.level_id==1"
          >
            <span>{{scope.row.partner_identity.get_pid.realname}}</span>
            <span>{{scope.row.partner_identity.get_pid.phone}}</span>
          </template>
        </el-table-column>
        <el-table-column label="联合发起人信息" prop align="center" width="120px">
          <template
            slot-scope="scope"
            v-if="scope.row.partner_identity&&scope.row.partner_identity.get_pid&&scope.row.partner_identity.get_pid.level_id==2"
          >
            <span>{{scope.row.partner_identity.get_pid.realname}}</span>
            <span>{{scope.row.partner_identity.get_pid.phone}}</span>
          </template>
        </el-table-column>
        <el-table-column label="核销时间" prop="verification_date" align="center" width="200px">
          <template slot-scope="scope">
            <span v-if="scope.row.verification_date">{{scope.row.verification_date}}</span>
            <!-- <span v-else></span> -->
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页 -->
      <div class="pagesCon">
        <div>
          <el-pagination
            :current-page="form.page"
            :page-sizes="page_sizes"
            :page-size="form.pagesize"
            layout="total, sizes, prev, pager, next, jumper"
            :total="page_totals"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
          />
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import axios from "axios";
import serv from "@/utils/request1";
import { partner_order_index, province ,Mechanism} from "@/api/NewRetailSystem";

// import commonFn from "@/utils/common";
import filter from "@/assets/filter";
export default {
  name: "GiftBagOrder",
  data() {
    return {
      use_time: [],
      pay_time: [],
      selectedOptions: [],
      options: [],
      Mechanisms:[],
      form: {
        page: 1,
        pagesize: 10
      },
      // 分页
      page_sizes: [10, 30, 50, 100], // 每页显示个数
      page_totals: 0, // 总条目数,
      statusType: [
        { name: "华悦口腔（口腔）", value: 2 },
        { name: "华视优选（眼科）", value: 3 },
        { name: "美分享PLUS（医美）", value: 4 }
      ],
      //列表数据数组
      tableData: [],
      // 列表loding
      tableLoading: false
    };
  },
  filters: {
    nullFn(opt) {
      if (opt) {
        return opt;
      } else {
        return "--";
      }
    },
    // 无数据显示
    noFn(opt) {
      if (opt) {
        return opt;
      } else {
        return "";
      }
    }
  },
  watch: {
    verification_date(val) {
      this.form["use_time"] = this.use_time
        ? this.use_time[0] + " - " + this.use_time[1]
        : "";
    }
  },
  created() {
  },
  //新加路由保存参数
  beforeRouteLeave(to, from, next) {
    // const answer = window.confirm("当前页面搜索条件将会被保存");
    //更新 put
    let keyname = this.$route.name;
    let value = JSON.stringify(this.form);
    sessionStorage.setItem(keyname, value);
    next();
  },

  mounted() {
    // 获取默认列表
    if (sessionStorage.getItem(this.$route.name)) {
      this.form = JSON.parse(sessionStorage.getItem(this.$route.name));
    }
    this.getList(this.form);
    this.getAreaList();
    this.getMechanismList()
  },
  methods: {
    toRoutes(name) {
      let route = { name };
      this.$router.push(route);
    },
    // 序号
    table_index(index) {
      return (this.form.page - 1) * this.form.pagesize + index + 1;
    },
    // 获取列表
    getList(e) {
      partner_order_index(e)
        .then(res => {
          console.log("xinagqing", res);
          if (res.data.code == 200) {
            this.tableData = res.data.data.data;
            this.page_totals = res.data.data.total;
          } else {
            this.$message({
              showClose: true,
              message: res.data.msg,
              type: "warning"
            });
          }
          this.tableLoading = false;
        })
        .catch(err => {
          this.errorStatus(err.msg);
          this.tableLoading = false;
        });
    },
    //获取地区列表
    getAreaList() {
      province().then(res => {
        console.log("res", res);
        // this.options = res.data.data;
        let arr=[]
        res.data.data.forEach(i => {
          if(i.app_type==2){
            i.app_type='-口腔'
          }else if(i.app_type==3){
            i.app_type='-眼科'
          }else{
            i.app_type='-医美'
          }
          arr.push({id:i.id,name:i.name+i.app_type})
        });
        this.options =arr
      });
    },
    //获取机构列表
    getMechanismList() {
      Mechanism().then(res => {
        console.log("res", res);
        this.Mechanisms = res.data.data;
      });
    },
    // 查询
    handleSearch() {
      this.form.page = 1;
      this.getList(this.form);
    },

    // 导出
    handleExport() {
      let datas = { ...this.form };
      delete datas.page;
      delete datas.pagesize;
      orderExport(datas)
        .then(res => {
          commonFn.downFile("导出", res);
        })
        .catch(err => {
          this.errorStatus(err.msg);
        });
    },
    // 改变页面条数
    handleSizeChange(val) {
      this.form.pagesize = val;
      this.getList(this.form);
    },
    // 选择页数
    handleCurrentChange(val) {
      this.form.page = val;
      this.getList(this.form);
    },
    // // 弹窗组件
    eleMsg(txt, status) {
      this.$message({
        showClose: true,
        message: txt,
        type: status
      });
    },
    // 失败状态弹窗
    errorStatus(txt) {
      this.eleMsg(txt, "error");
    }
  }
};
</script>
<style scoped>
.app-container {
  padding: 20px !important;
  background: transparent;
}
/* 主页列表样式 */
.listDiv {
  margin-bottom: 20px;
  padding: 0 20px;
}
.formDiv {
  padding: 20px;
}
.el-range-editor--medium.el-input__inner {
  width: 205px;
}
.pagesCon {
  text-align: right;
  margin-top: 20px;
}
.allCenter {
  text-align: center;
}
.spanToInput {
  width: 205px;
  min-height: 30px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: block;
  border: 1px solid #ddd;
  text-align: left;
  padding: 0 12px;
}
.line {
  height: 25px;
  background: #f7f7f7;
}
.recommend {
  min-width: 280px;
  color: #1d2023;
  text-align: center;
  font-size: 16px;
  margin-left: 25px;
}
.boxContent {
  margin-top: 20px;
  height: 25px;
  line-height: 25px;
  border: 1px solid #ddd;
  text-align: center;
  padding: 0 12px;
}
.arrow {
  text-align: center;
  padding: 12px 0 0 0;
}
.fontColor {
  font-size: 16px;
  text-align: center;
  margin-bottom: 15px;
}
.mb_20 {
  font-size: 20px;
  text-align: center;
  margin-top: 20px;
}
</style>